<script setup>
  import {
    Document,
    Menu as IconMenu,
    Location,
    Setting,
  } from '@element-plus/icons-vue'
  // 导入userinfostore
  import { useUserInfoStore } from '@/store/userinfo'
  const userInfoStore = useUserInfoStore()
  import { useRouter } from 'vue-router'
  // const state = reactive({
  //   circleUrl: userInfoStore.userInfo.image_url,
  // })

  // 退出登录
  const router = useRouter()
  const goLogin = () => {
    localStorage.removeItem('token')
    localStorage.removeItem('id')
    router.replace('/login')
  }
  const identityRoutes = router.options.routes.filter(
    (item) => item.name == 'menu'
  )[0].children

  const iconStr = (str) => {
    console.log(typeof `<${str}/>`)
    return `<${str}/>`
  }
</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-aside>
        <el-scrollbar height="100vh">
          <el-menu
            background-color="#2b303b"
            class="el-menu-vertical-demo"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
          >
            <div class="title">通用后台管理系统</div>
            <template v-for="item in identityRoutes">
              <template v-if="!item.children">
                <el-menu-item :index="item.path">
                  <el-icon v-if="item.meta?.icon">
                    <!-- 图标 -->
                    <component class="icons" :is="item.meta.icon" />
                    <!-- {{ iconStr(item.meta?.icon) }} -->
                  </el-icon>
                  <span>{{ item.meta?.title }}</span>
                </el-menu-item>
              </template>
              <template v-else>
                <el-sub-menu :index="item.path">
                  <template #title>
                    <el-icon>
                      <TakeawayBox />
                    </el-icon>
                    <span>{{ item.meta?.title }}</span>
                  </template>
                  <el-menu-item
                    :index="obj.path"
                    v-for="obj in item.children"
                    >{{ obj.meta?.title }}</el-menu-item
                  >
                </el-sub-menu>
              </template>
            </template>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-container>
        <el-header>
          <span class="header-left-content"
            >尊敬的
            {{ userInfoStore.userInfo.name || userInfoStore.userInfo.account }}
            欢迎您登录本系统</span
          >
          <div class="header-right-content">
            <el-icon :size="20" class="message">
              <Message />
            </el-icon>
            <el-avatar size="24" :src="userInfoStore.userInfo.image_url" />
            <el-dropdown>
              <span class="el-dropdown-link"> 设置 </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>设置账号</el-dropdown-item>
                  <el-dropdown-item>更改头像</el-dropdown-item>
                  <el-dropdown-item @click="goLogin">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </el-header>
        <el-main>
          <div class="con">
            <router-view></router-view>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style lang="scss" scoped>
  @import './index.css';
</style>
